package com.hunau.iot.server.common.persist;

import com.hunau.iot.server.utils.SpringContextUtils;
import com.hunau.system.domain.TbEnergy;
import com.hunau.system.domain.TbEnvironment;
import com.hunau.system.domain.TbIoterminal;
import com.hunau.system.service.impl.TbEnergyServiceImpl;
import com.hunau.system.service.impl.TbEnvironmentServiceImpl;
import com.hunau.system.service.impl.TbIoterminalServiceImpl;

/**
 * @program: ruoyi
 * @description: mysql
 * @author: Mr.Liu
 * @create: 2020-03-24 11:13
 **/
public class Memery implements BaseMo{
    private static TbEnvironmentServiceImpl tbEnvironmentService = (TbEnvironmentServiceImpl) SpringContextUtils.getBeanByClass(TbEnvironmentServiceImpl.class);
    private static TbEnergyServiceImpl tbEnergyService = (TbEnergyServiceImpl) SpringContextUtils.getBeanByClass(TbEnergyServiceImpl.class);
    private static TbIoterminalServiceImpl tbIoterminalService = (TbIoterminalServiceImpl) SpringContextUtils.getBeanByClass(TbIoterminalServiceImpl.class);

    @Override
    public boolean insert(Object msg) {
        if(msg instanceof TbEnvironment){
            return tbEnvironmentService.insertTbEnvironment((TbEnvironment)msg)>0;
        }
        if(msg instanceof TbEnergy){
            return tbEnergyService.insertTbEnergy((TbEnergy)msg)>0;
        }
        return false;
    }

    @Override
    public boolean update(Object msg) {
        if(msg instanceof TbIoterminal){
            return tbIoterminalService.updateTbIoterminal((TbIoterminal) msg)>0;
        }
        return false;
    }
}
